package com.airlines.crewassignment.service.basicinfo.impl;

import com.airlines.base.service.base.impl.BaseServiceImpl;
import com.airlines.crewassignment.dao.basicinfo.AuthorizedStrengthMapper;
import com.airlines.crewassignment.entity.basicinfo.AuthorizedStrength;
import com.airlines.crewassignment.service.basicinfo.AuthorizedStrengthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xxxx
 * @date 2018/8/7
 * @company xxxx Airlines
 * @description
 */
@Service
public class AuthorizedStrengthServiceImpl extends BaseServiceImpl<AuthorizedStrength,String> implements AuthorizedStrengthService {

    @Autowired
    private AuthorizedStrengthMapper authorizedStrengthMapper;

    @Autowired
    @Override
    public void setBaseMapper() {
       super.setBaseMapper(authorizedStrengthMapper);
    }

    @Override
    public AuthorizedStrength getByCrewIdAndSerial(AuthorizedStrength authorizedStrength) {
        return authorizedStrengthMapper.getByCrewIdAndSerial(authorizedStrength);
    }

    @Override
    public Integer delete(AuthorizedStrength authorizedStrength) {
        //获取大于当前的所有
        List<AuthorizedStrength> list = authorizedStrengthMapper.getListForDelete(authorizedStrength);
        authorizedStrengthMapper.delete(authorizedStrength);
        if(list != null && list.size()>0){
            for(AuthorizedStrength as:list){
                as.setSerialNo(as.getSerialNo()-1);
                authorizedStrengthMapper.updateByPrimaryKeySelective(as);
            }
        }
        return 1;
    }

    @Override
    public String getTechNamesByTechNoArr(String[] techNoArr) {
        Map map = new HashMap();
        map.put("techNoArr",techNoArr);
        String result = authorizedStrengthMapper.getTechNamesByTechNoArr(map).replaceAll(",","/");
        return result;
    }
}
